home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Info 1994 March
/
Internet Info CD-ROM (Walnut Creek) (March 1994).iso
/
networking
/
mail
/
mh
/
contrib
/
multimedia
/
mhweather.shar
/
mail.weather.ext
next >
Wrap
Text File
|
1993-03-15
|
7KB
|
329 lines
#!/usr/bin/perl
#
# mail.weather.ext - mail today's weather report using external body parts
#
# Usage: mail.weather [-debug] [-help] [-key file] [-verbose] address ...
#
# Author: Jerry Sweet <jsweet@irvine.com>
#
# $Header: /sparc/users/jsweet/src/weather/mhweather/RCS/mail.weather.ext,v 1.16 1993/03/07 08:43:40 jsweet Exp $
#
# Subprograms
#
sub gripe {
print STDERR "$prog: ", @_, "\n";
}
sub barf {
&gripe(@_);
exit 1;
}
sub cmd {
local($_, $exit_on_error) = @_;
local($st);
if ($debug || $verbose) {
print "\t$_\n";
}
$st = system "$_";
if ($st >> 8 && $exit_on_error) {
split;
&barf("$_[0] failed with status ", $st >> 8);
}
}
sub sh {
# Shell command, exit on error.
local($_) = @_;
&cmd($_, 1);
}
sub one_hour_earlier {
local($tt_hour, $tt_mday, $tt_mon) = @_;
if (--$tt_hour < 0) {
$tt_hour = 23;
if (--$tt_mday < 0) {
if (--$tt_mon < 0) {
$tt_mon = 11;
}
$tt_mday = $lastday[$tt_mon];
}
}
($tt_hour, $tt_mday, $tt_mon);
}
sub read_profile {
# Defines associative array %PROFILE_COMPONENT indexed by lower case
# component name. Continuation lines are tacked on. New
# occurrences of a component wipe out previous occurrences of the
# same component, but probably shouldn't.
local($profile) = defined $ENV{'MH'} ? $ENV{'MH'} :
$ENV{'HOME'} . "/.mh_profile";
local($profile_component) = 'x-bogus';
local($_);
&barf("can't open profile \"$profile\" - $!")
unless open(PROFILE, "<$profile");
while (<PROFILE>) {
/^(\S+):\s*/ && do {
($profile_component = $1) =~ tr/A-Z/a-z/;
$_ = $';
s/\s+$//;
$PROFILE_COMPONENT{$profile_component} = $_;
};
/^[ \t]/ && do {
s/\s+$//;
$PROFILE_COMPONENT{$profile_component} .= $_;
};
}
}
sub ext_local_file {
local($type, $explanation, $name, $site) = @_;
local($continue);
$continue = $site ? "; \\\\" : '';
print FORM <<"xxEndExternLocalFile";
#@$type [$explanation] \\
access-type=local-file; \\
name="$name"$continue
xxEndExternLocalFile
if ($site) {
print FORM "\tsite=\"$site\"\n";
}
}
sub ext_anon_ftp {
local($type, $explanation, $site, $dir, $name, $expiration, $size) = @_;
local($continue);
$continue = ($expiration || $size) ? "; \\" : '';
print FORM <<"xxEndExternAnonFTPxx";
#@${type} [${explanation}] \\
access-type=anon-ftp; \\
name="${name}"; \\
directory="${dir}"; \\
site="${site}"${continue}
xxEndExternAnonFTPxx
$continue = $size ? "; \\" : '';
if ($expiration) {
print FORM "\texpiration=\"${expiration}\"${continue}\n";
}
if ($size) {
print FORM "\tsize=${size}\n";
}
}
sub ftp_gif {
local($explanation, $name, $exp, $size) = @_;
&ext_anon_ftp('image/gif', $explanation, $wsite, $wdir, $name, $exp, $size);
}
#
# Main
#
($prog = $0) =~ s|.*/||;
$paths = '/usr/local/bin/mh:/usr/local/bin';
$ENV{'MHCONTEXT'} = '/dev/null'; # No context changes here...
$ENV{'PATH'} = $ENV{'HOME'} . '/bin:' . $paths . ':' . $ENV{'PATH'};
$wsite = 'vmd.cso.uiuc.edu';
$wdir = 'wx';
$wxkey = 'WXKEY.GIF';
# Check the profile.
&read_profile;
if (defined $PROFILE_COMPONENT{$prog}) {
push(@Args, split(' ', $PROFILE_COMPONENT{$prog}));
}
# Check the command line arguments.
push(@Args, @ARGV);
while ($_ = shift @Args) {
/^-debug$/ && do { $debug++; next; };
/^-help$/ && do {
print <<"xxEndHelpxx";
$prog - mail today's weather report
Usage: $prog [-(no)debug] [-help] [-key file] [-(no)verbose] address ...
Options:
-debug print the message draft and invoke default whatnow
-help print this message
-key file local path to weather key image file; FTP-ed if omitted
-verbose print shell commands as they're executed
address destination e-mail address(es)
xxEndHelpxx
exit 1;
};
/^-key$/ && do {
$keyfile = shift @Args;
next;
};
/^-nodebug$/ && do { --$debug; next; };
/^-noverbose$/ && do { --$verbose; next; };
/-verbose$/ && do { ++$verbose; next; };
/^[^\-]/ && do {
push(@address, $_);
next;
};
&barf("unrecognized command line option \"$_\"");
}
$debug = $debug > 0;
$verbose = $verbose > 0;
&barf("no destination e-mail address specified")
unless $#address >= 0;
if ($keyfile && ! -r $keyfile) {
$keyfile = '';
}
$recipients = join (', ', @address);
$formfile = "/tmp/$prog.$$";
&barf("can't open temporary formfile $formfile - $!") unless
open(FORM, ">$formfile");
# Figure out which file to get; if we're not past the half-hour mark,
# use the previous hour's file.
($tt_sec,$tt_min,$tt_hour,$tt_mday,$tt_mon,$tt_year,$tt_wday,
$tt_yday,$tt_isdst) = gmtime(time);
@lastday = (31, ($tt_year % 4 == 0) ? 29 : 28,
31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if ($tt_min < 30) {
($tt_hour, $tt_mday, $tt_mon) =
&one_hour_earlier($tt_hour, $tt_mday, $tt_mon);
}
$datestr = sprintf("%02d%02d%02d", $tt_mon + 1, $tt_mday, $tt_hour);
$gmt = sprintf("%02d/%02d %02d00 GMT", $tt_mon + 1, $tt_mday, $tt_hour);
$sagmt = sprintf("%02d00 GMT %02d/%02d", $tt_hour, $tt_mon + 1, $tt_mday);
$surface_analysis_gif = sprintf("SA%s.GIF", $datestr);
($ett_hour, $ett_mday, $ett_mon) =
&one_hour_earlier($tt_hour, $tt_mday, $tt_mon);
$e_datestr = sprintf("%02d%02d%02d", $ett_mon + 1, $ett_mday, $ett_hour);
$egmt = sprintf("%02d00 GMT %02d/%02d", $ett_hour, $ett_mon + 1, $ett_mday);
$satellite_photo_gif = sprintf("CI%s.GIF", $e_datestr);
@m_name = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec');
$exp_hour = $tt_hour;
$exp_mday = $tt_mday;
$exp_mon = $tt_mon;
$exp_year = $tt_year;
if (++$exp_mday > $lastday[$exp_mon]) {
$exp_mday = 1;
if (++$exp_mon > 11) {
$exp_mon = 1;
if (++$exp_year > 99) {
$exp_year = 0;
}
}
}
$expire_time = sprintf(
"%d %s %02d %02d:%02d:%02d GMT",
$exp_mday, $m_name[$exp_mon], $exp_year,
$exp_hour, 0, 0);
$inum = $keyfile ? 'two' : 'three';
# Print the mhn composition template:
print FORM <<"xxEndForm10xx";
To: $recipients
Subject: weather report: $gmt
--------
#<text/richtext [explanation]
<paragraph>You may FTP $inum images:</paragraph>
<paragraph><indent><fixed>
$surface_analysis_gif: surface analysis at $sagmt<nl>
xxEndForm10xx
if (! $keyfile) {
print FORM <<"xxEndForm15xx";
$wxkey: map symbol key<nl>
xxEndForm15xx
}
print FORM <<"xxEndForm20xx";
$satellite_photo_gif: satellite photo at $egmt
</fixed></indent></paragraph>
#
#begin [weather report: $gmt] parallel
xxEndForm20xx
&ftp_gif('surface analysis + radar summary',
$surface_analysis_gif, $expire_time, 50000);
$keyfile ?
&ext_local_file('image/gif', 'weather map symbol key', $keyfile) :
&ftp_gif('weather map symbol key', $wxkey, 0, 18867);
&ftp_gif('satellite photo', $satellite_photo_gif, $expire_time, 170000);
print FORM "#end\n";
&barf("problem closing formfile $formfile - $!") unless
close(FORM);
if ($debug) {
system '/bin/cat', $formfile;
}
if ($debug) {
&sh("comp -form $formfile -noedit");
}
else {
&sh("comp -form $formfile -whatnowproc mhnsend");
}
unlink $formfile;
exit 0;